<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>案例-背景图片</title>
    <style>
        .div1 {
            width: 300px;
            height: 200px;
            margin: 0 auto;
            background-image: url(./image/横屏图片.png);
            /*默认平铺*/
            background-size: contain;
            /*拉伸图片以适应元素大小*/
            background-repeat: no-repeat;
            /*不平铺*/
            transition: width 0.5s, height 0.5s;
            /*平滑变化*/
        }

        .div1:hover {
            width: 400px;
            height: 300px;
        }

        .div3 {
            width: 300px;
            height: 200px;
            margin: 0 auto;
            background-image: url(./image/横屏图片2.png);
            /*默认平铺*/
            background-size: contain;
            /*拉伸图片以适应元素大小*/
            background-repeat: no-repeat;
            /*不平铺*/
            transition: width 0.5s, height 0.5s;
            /*平滑变化*/
        }

        .div3:hover {
            width: 400px;
            height: 300px;
        }

        .div2 {
            position: relative;
            width: 100%;
            height: 40px;
            font-size: 20px;
            margin: 0 auto;
            background-color: rgb(168, 167, 165, 0.5);
            text-align: center;
            color: aliceblue;
        }

        span {
            position: absolute;
            font-weight: 700;
            top: 5px;
            left: 38%;
        }
    </style>
</head>

<body>
    <div class="div1">
        <div class="div2"><span>绝美星空</span></div>
    </div><br>
    <div class="div3"></div>
</body>

</html>